#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import time
from django.utils.deprecation import MiddlewareMixin


class RequestLoggingMiddleware(MiddlewareMixin):
    """
    记录一下请求日志，接口的响应时间
    """

    def process_request(self, request):
        request.start_time = time.time()

    def process_response(self, request, response):
        cost_time = time.time() - request.start_time
        path = request.path
        method = request.method
        print("request path:{},method:{},cost_time:{}".format(path, method, cost_time))
        return response
